﻿using System;
using DynCMS.NET.Core.Entities;
using DynCMS.NET.Core.Interfaces;
using DynCMS.NET.Infrastructure.IOC;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace DynCMS.NET.DataAccess.Test
{
    [TestClass]
    public class PageRepositoryTest : BaseDataContextTest
    {
        [TestMethod]
        public void GetInstanceTest()
        {
            var repo = IOCProvider.Instance.Resolve<IDataRepository<Page>>();
            Assert.IsNotNull(repo);
        }

        [TestMethod]
        public void CreateTest()
        {
            var page = new DynCMS.NET.Core.Entities.Page()
            {
                Url = "~",
                ParentUrl = "~",
                Children = new System.Collections.Generic.List<Page>()
            };
            page.Parent = page;
            page.Children.Add(page);

            var repo = IOCProvider.Instance.Resolve<IDataRepository<Page>>();
            var created = repo.Create(page);
            Assert.AreSame(page, created);

            var saved = repo.Get(page);
            Assert.AreSame(page.Url, saved.Url);
        }
    }
}